/*
vue3组合api:
   setup
   onBeforeMount
   onMounted
   onBeforeUpdate
   onUpdated
   onBeforeUnmount
   onUnmounted
*/

import { onBeforeUnmount, ref } from 'vue'
export const useWidth = () => {
  const width = ref(window.innerWidth)
  const onResize = () => {
    width.value = window.innerWidth
    console.log('onResize')
  }
  window.addEventListener('resize', onResize)
  onBeforeUnmount(() => {
    window.removeEventListener('resize', onResize)
  })
  return { width }
}
